.class public Lcom/glympse/platform/GHttpConnection;
.super Ljava/lang/Object;
.source "GHttpConnection.java"


# static fields
.field public static final GET:I = 0x0

.field public static final HTTP_CREATED:I = 0xc9

.field public static final HTTP_OK:I = 0xc8

.field public static final POST:I = 0x1


# instance fields
.field private m_oHttpURLConnection:Ljava/net/HttpURLConnection;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 25
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 33
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    .line 25
    return-void
.end method

.method public static Create(Ljava/lang/String;)Lcom/glympse/platform/GHttpConnection;
    .locals 9
    .parameter "strUrl"

    .prologue
    .line 42
    const/4 v2, 0x0

    .line 46
    .local v2, oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    :try_start_0
    new-instance v6, Ljava/net/URL;

    invoke-direct {v6, p0}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    .line 47
    .local v6, oUrl:Ljava/net/URL;
    invoke-virtual {v6}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;

    move-result-object v4

    check-cast v4, Ljava/net/HttpURLConnection;

    .line 51
    .local v4, oHttpURLConnection:Ljava/net/HttpURLConnection;
    const v7, 0xafc8

    invoke-virtual {v4, v7}, Ljava/net/HttpURLConnection;->setConnectTimeout(I)V

    .line 55
    invoke-virtual {v6}, Ljava/net/URL;->getProtocol()Ljava/lang/String;

    move-result-object v7

    const-string v8, "https"

    invoke-virtual {v7, v8}, Ljava/lang/String;->equalsIgnoreCase(Ljava/lang/String;)Z

    move-result v7

    if-eqz v7, :cond_0

    .line 57
    move-object v0, v4

    check-cast v0, Ljavax/net/ssl/HttpsURLConnection;

    move-object v5, v0

    .line 58
    .local v5, oHttpsURLConnection:Ljavax/net/ssl/HttpsURLConnection;
    new-instance v7, Lorg/apache/http/conn/ssl/BrowserCompatHostnameVerifier;

    invoke-direct {v7}, Lorg/apache/http/conn/ssl/BrowserCompatHostnameVerifier;-><init>()V

    invoke-virtual {v5, v7}, Ljavax/net/ssl/HttpsURLConnection;->setHostnameVerifier(Ljavax/net/ssl/HostnameVerifier;)V

    .line 61
    .end local v5           #oHttpsURLConnection:Ljavax/net/ssl/HttpsURLConnection;
    :cond_0
    const/4 v7, 0x0

    invoke-virtual {v4, v7}, Ljava/net/HttpURLConnection;->setAllowUserInteraction(Z)V

    .line 62
    new-instance v3, Lcom/glympse/platform/GHttpConnection;

    invoke-direct {v3}, Lcom/glympse/platform/GHttpConnection;-><init>()V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    .line 63
    .end local v2           #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    .local v3, oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    :try_start_1
    iput-object v4, v3, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1

    move-object v2, v3

    .line 70
    .end local v3           #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    .end local v4           #oHttpURLConnection:Ljava/net/HttpURLConnection;
    .end local v6           #oUrl:Ljava/net/URL;
    .restart local v2       #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    :goto_0
    return-object v2

    .line 65
    :catch_0
    move-exception v7

    move-object v1, v7

    .line 67
    .local v1, e:Ljava/lang/Exception;
    :goto_1
    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0

    .line 65
    .end local v1           #e:Ljava/lang/Exception;
    .end local v2           #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    .restart local v3       #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    .restart local v4       #oHttpURLConnection:Ljava/net/HttpURLConnection;
    .restart local v6       #oUrl:Ljava/net/URL;
    :catch_1
    move-exception v7

    move-object v1, v7

    move-object v2, v3

    .end local v3           #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    .restart local v2       #oHttpConnection:Lcom/glympse/platform/GHttpConnection;
    goto :goto_1
.end method


# virtual methods
.method public Close()V
    .locals 1

    .prologue
    .line 211
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v0}, Ljava/net/HttpURLConnection;->disconnect()V

    .line 212
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    .line 213
    return-void
.end method

.method public GetContentLength()I
    .locals 1

    .prologue
    .line 147
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v0}, Ljava/net/HttpURLConnection;->getContentLength()I

    move-result v0

    return v0
.end method

.method public GetDate()J
    .locals 4

    .prologue
    .line 153
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    const-string v1, "Date"

    const-wide/16 v2, 0x0

    invoke-virtual {v0, v1, v2, v3}, Ljava/net/HttpURLConnection;->getHeaderFieldDate(Ljava/lang/String;J)J

    move-result-wide v0

    return-wide v0
.end method

.method public GetHeaderField(Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "strField"

    .prologue
    .line 97
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v1, p1}, Ljava/net/HttpURLConnection;->getHeaderField(Ljava/lang/String;)Ljava/lang/String;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 103
    :goto_0
    return-object v1

    .line 99
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 101
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .line 103
    const/4 v1, 0x0

    goto :goto_0
.end method

.method public GetResponseCode()I
    .locals 5

    .prologue
    const/4 v4, 0x0

    .line 114
    :try_start_0
    iget-object v2, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v2}, Ljava/net/HttpURLConnection;->getResponseCode()I
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result v2

    .line 135
    .end local p0
    :goto_0
    return v2

    .line 116
    .restart local p0
    :catch_0
    move-exception v2

    .line 124
    :try_start_1
    iget-object v2, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    const-string v3, "status"

    invoke-virtual {v2, v3}, Ljava/net/HttpURLConnection;->getHeaderField(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v1

    .line 125
    .local v1, strStatus:Ljava/lang/String;
    invoke-static {v1}, Lcom/glympse/platform/common/Helpers;->IsEmpty(Ljava/lang/String;)Z

    move-result v2

    if-nez v2, :cond_0

    .line 127
    const/16 v2, 0x20

    invoke-static {v1, v2}, Lcom/glympse/platform/common/Helpers;->StrSplit(Ljava/lang/String;C)Lcom/glympse/platform/GVector$Strings;

    move-result-object v2

    const/4 v3, 0x0

    invoke-virtual {v2, v3}, Lcom/glympse/platform/GVector$Strings;->elementAt(I)Ljava/lang/Object;

    move-result-object p0

    .end local p0
    check-cast p0, Ljava/lang/String;

    invoke-static {p0}, Lcom/glympse/platform/common/Helpers;->ParseInt(Ljava/lang/String;)I
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1

    move-result v2

    goto :goto_0

    .line 130
    .end local v1           #strStatus:Ljava/lang/String;
    :catch_1
    move-exception v2

    move-object v0, v2

    .line 132
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .end local v0           #e:Ljava/lang/Exception;
    :cond_0
    move v2, v4

    .line 135
    goto :goto_0
.end method

.method public OpenInputStream()Ljava/io/InputStream;
    .locals 4

    .prologue
    .line 163
    const/4 v1, 0x0

    .line 166
    .local v1, oStream:Ljava/io/InputStream;
    :try_start_0
    iget-object v2, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v2}, Ljava/net/HttpURLConnection;->getInputStream()Ljava/io/InputStream;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 177
    :goto_0
    if-nez v1, :cond_0

    .line 179
    const-string v2, "Failed to get input stream.  Attempting to get error stream."

    invoke-static {v2}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V

    .line 182
    :try_start_1
    iget-object v2, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v2}, Ljava/net/HttpURLConnection;->getErrorStream()Ljava/io/InputStream;

    move-result-object v1

    .line 183
    new-instance v2, Ljava/lang/StringBuilder;

    const-string v3, "Error stream: "

    invoke-direct {v2, v3}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    if-nez v1, :cond_1

    const-string v3, "null"

    :goto_1
    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-static {v2}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/String;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_1

    .line 191
    :cond_0
    :goto_2
    return-object v1

    .line 168
    :catch_0
    move-exception v2

    move-object v0, v2

    .line 170
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_0

    .line 183
    .end local v0           #e:Ljava/lang/Exception;
    :cond_1
    :try_start_2
    const-string v3, "not null"
    :try_end_2
    .catch Ljava/lang/Exception; {:try_start_2 .. :try_end_2} :catch_1

    goto :goto_1

    .line 185
    :catch_1
    move-exception v2

    move-object v0, v2

    .line 187
    .restart local v0       #e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    goto :goto_2
.end method

.method public OpenOutputStream()Ljava/io/OutputStream;
    .locals 2

    .prologue
    .line 199
    :try_start_0
    iget-object v1, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v1}, Ljava/net/HttpURLConnection;->getOutputStream()Ljava/io/OutputStream;
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    move-result-object v1

    .line 205
    :goto_0
    return-object v1

    .line 201
    :catch_0
    move-exception v1

    move-object v0, v1

    .line 203
    .local v0, e:Ljava/lang/Exception;
    invoke-static {v0}, Lcom/glympse/platform/common/Helpers;->Log(Ljava/lang/Throwable;)V

    .line 205
    const/4 v1, 0x0

    goto :goto_0
.end method

.method public SetContentLength(I)V
    .locals 1
    .parameter "nBytes"

    .prologue
    .line 141
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v0, p1}, Ljava/net/HttpURLConnection;->setFixedLengthStreamingMode(I)V

    .line 142
    return-void
.end method

.method public SetRequestMethod(I)V
    .locals 2
    .parameter "nMethod"

    .prologue
    const/4 v1, 0x1

    .line 76
    if-nez p1, :cond_1

    .line 78
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    const/4 v1, 0x0

    invoke-virtual {v0, v1}, Ljava/net/HttpURLConnection;->setDoOutput(Z)V

    .line 84
    :cond_0
    :goto_0
    return-void

    .line 80
    :cond_1
    if-ne v1, p1, :cond_0

    .line 82
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v0, v1}, Ljava/net/HttpURLConnection;->setDoOutput(Z)V

    goto :goto_0
.end method

.method public SetRequestProperty(Ljava/lang/String;Ljava/lang/String;)V
    .locals 1
    .parameter "strField"
    .parameter "strValue"

    .prologue
    .line 89
    iget-object v0, p0, Lcom/glympse/platform/GHttpConnection;->m_oHttpURLConnection:Ljava/net/HttpURLConnection;

    invoke-virtual {v0, p1, p2}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

    .line 90
    return-void
.end method
